using System.Data.Entity.ModelConfiguration;

namespace InvestmentIntelligence.DbModel.Models.Mapping
{
    public class FundBookEntityMap : EntityTypeConfiguration<FundBookEntity>
    {
        public FundBookEntityMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.OriginalId)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.Name)
                .IsRequired()
                .HasMaxLength(100);

            // Table & Column Mappings
            this.ToTable("FundBookEntity", "TradingData");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.OriginalId).HasColumnName("OriginalId");
            this.Property(t => t.ParentId).HasColumnName("ParentId");
            this.Property(t => t.Name).HasColumnName("Name");
            this.Property(t => t.CurrencyId).HasColumnName("CurrencyId");
            this.Property(t => t.IsActive).HasColumnName("IsActive");
            this.Property(t => t.HasOpenPosition).HasColumnName("HasOpenPosition");

            // Relationships
            this.HasRequired(t => t.Currency);

            this.HasOptional(t => t.Fund)
                .WithMany(t => t.FundBooks)
                .HasForeignKey(d => d.ParentId);

        }
    }
}
